package com.febers.ihealth.base

import android.os.Bundle
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar

abstract class BaseActivity: AppCompatActivity() {

    private var focusChange = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(setView())
        setSupportActionBar(setToolbar())
        supportActionBar?.apply {
            title = setToolbarTitle() ?: ""
        }
        initView()
    }

    override fun onWindowFocusChanged(hasFocus: Boolean) {
        super.onWindowFocusChanged(hasFocus)
        if (!focusChange) {
            afterCreate()
            focusChange = true
        }
    }

    open fun initView() { }

    open fun setToolbar(): Toolbar? = null

    open fun setToolbarTitle(): String? = null

    abstract fun setView(): Int

    abstract fun afterCreate()
}